package com.springbootbase.springbootproject.mapper;


import com.springbootbase.springbootproject.pojo.Student;
import com.springbootbase.springbootproject.pojo.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface StudentMapper {
    @Select("select * from studentinfo where id =#{id}")
    Student findById(Long id);


    @Update("UPDATE studentinfo SET `rank` = #{rank}, university = #{university}, department = #{department}, major = #{major}, searchWay = #{searchWay}, paperNum = #{paperNum}, hobby = #{hobby}, email = #{email}, phone = #{phone}, majorRank = #{majorRank} WHERE id = #{id}")
    void updateStudent(Student student);

    @Select("SELECT * FROM studentinfo where exists(select 1 from user where user.id=#{id} and userType='admin') limit #{offset}, #{size}")
    ArrayList<Student> getList(Long id, Integer offset, Integer size);

    @Select("select username from user where id=#{id}")
    String getNameById(Long id);

    @Select("SELECT COUNT(*) FROM studentinfo where exists(select 1 from user where user.id=#{id} and userType='admin')")
    int countAllStudentInfo(Long id);


    @Select("select * from studentinfo where id=#{id}")
    Student getStudent(Long id);

    @Select("select * from studentinfo")
    List<Student> getStudentList();

    @Select("select * from teacherinfo")
    List<Teacher> getTeacherList();
}

